package com.jiamingZhao.utils;

import java.util.Optional;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author ：JiaMing Zhao
 * @since ：2025/6/6 14:27
 */
public class MpUtil {

    /**
     * 字符串去除空白内容
     *
     * <ul> <li>'"<>&*+=#-; sql注入黑名单</li> <li>\n 回车</li> <li>\t 水平制表符</li> <li>\s 空格</li> <li>\r 换行</li> </ul>
     */
    private static final Pattern REPLACE_BLANK = Pattern.compile("'|\"|\\<|\\>|&|\\*|\\+|=|#|-|;|\\s*|\t|\r|\n");

    private MpUtil(){

    }


    public static <T, R> R mapOrderDefault(T t, Function<T, R> function, R defaultValue) {
        return Optional.ofNullable(t)
                .map(function).orElse(defaultValue);
    }

    public static <T> T getDefault(T t, T defaultValue) {
        return Optional.ofNullable(t).orElse(defaultValue);
    }



    public static String replaceAllBlank(String str) {
        Matcher matcher = REPLACE_BLANK.matcher(str);
        return matcher.replaceAll("");
    }
}
